package com.itly.rwyxm.controller;

import com.itly.rwyxm.pojo.Code;
import com.itly.rwyxm.pojo.Result;
import com.itly.rwyxm.pojo.User;
import com.itly.rwyxm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 
 * @Version: 1.0
 * @Date: 2023-11-21-12:35
 * @Description: 用户
 */
@Controller
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;
    /**
     * 登录
     * @return 登录验证
     */
    @PostMapping("/login")
    @ResponseBody
    public Result login(@RequestBody User user) {
        System.out.println(user.toString());
        boolean flag = userService.login(user);
        return new Result(flag ? Code.GET_OK : Code.GET_ERR, flag);
    }

    /**
     * 注册
     * @return 注册验证
     */
    @PostMapping("/register")
    @ResponseBody
    public Result register(@RequestBody User user) {
        System.out.println(user.toString());
        boolean flag = userService.insert(user);
        return new Result(flag ? Code.SAVE_OK: Code.SAVE_ERR, flag);
    }
}
